<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/3
  Time: 10:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="js/jquery-1.8.3.js"></script>
<html>
<head>
    <title>水果查询</title>
    <style>
        #box {
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div id="box">
    <table id="table" border="1px solid black">
        <tr>
            <td>类别</td>
            <td>品种</td>
            <td>产地</td>
            <td>总重量(公斤)</td>
            <td>单价(元/公斤)</td>
            <td>操作</td>
        </tr>
        <c:forEach var="list" items="${list}">
            <tr>
                <td>${list.type}</td>
                <td>${list.breed}</td>
                <td>${list.area}</td>
                <td>${list.weight}</td>
                <td>${list.price}</td>
                <td><a href="detail?id=${list.id}">详情</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"
                                                                                      onclick="dele(${list.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>
<script>
    $(function () {
        $("#table tr:odd").css("background", "#cfe5d9")
        $("#table tr:even").css("background", "#cfe4e5")
    })

    function dele(id) {
        if (confirm("确定要删除吗?")) {
            $.post(
                "delete", {"id": id}, function (data) {
                    if (data == "true") {
                        alert("删除成功")
                        location.href="list"
                    }else {
                        alert("删除失败")
                        location.href="list"
                    }
                }
            )
        }
    }
</script>
</html>
